package com.bruce.demo2.patterns.demo2.structural.demo11.composite;

/**
 * @PROJECT_NAME: design_patterns
 * @DESCRIPTION: 菜单组件 不管是菜单还是菜单项 都应该继承该类
 * @AUTHOR: CNBruceLee
 * @DATE: 2021/7/29 7:12
 */
public abstract class MenuComponent {
    protected String name;
    protected int level;
    protected MenuComponent parentMenu;

    public MenuComponent(String name, int level, MenuComponent parentMenu) {
        this.name = name;
        this.level = level;
        this.parentMenu = parentMenu;
    }

    /**
     * 添加菜单
     * 叶子几点无需此方法，因此需要子类根据不同情况进行重写，
     * 为什么不改成抽象方法呢？抽象的子类必须进行实现，但是叶子几点无需此方法，在写一遍实现抛送异常吗？
     *
     * @param menuComponent
     */
    public void add(MenuComponent menuComponent) {
        throw new UnsupportedOperationException();
    }

    /**
     * 移除菜单
     *
     * @param menuComponent
     */
    public void remove(MenuComponent menuComponent) {
        throw new UnsupportedOperationException();
    }

    /**
     * 获取指定的子菜单
     *
     * @param i
     */
    public MenuComponent getChild(int i) {
        throw new UnsupportedOperationException();
    }

    /**
     * 获取菜单名
     *
     * @return
     */
    public String getName() {
        return name;
    }

    /**
     * 获取所属菜单
     *
     * @return
     */
    public MenuComponent getParentMenu() {
        return parentMenu;
    }

    /**
     * 打印菜单
     */
    public void print() {
        throw new UnsupportedOperationException();
    }
}
